package Com.amit.Collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

class Student1
{
	int age;
	String name;
	String address;
	
	public Student1(int age, String name, String address) {
		super();
		this.age = age;
		this.name = name;
		this.address = address;
	}
	
}

class AgeComparator implements Comparator

{

	@Override
	public int compare(Object o1, Object o2) {
		
		Student1 s1=(Student1) o1;
		
		Student1 s2=(Student1) o2;
		
		if(s1.age==s2.age)
		{
			return 0;
		}
		else if(s1.age>s2.age)
		{
			return 1;
		}
		else
		{
			return -1;
		}
		
		
	}
	
}

class NameComparator implements Comparator

{

	@Override
	public int compare(Object o1, Object o2) {
		
		Student1 s1=(Student1) o1;
		
		Student1 s2=(Student1) o2;
		return s1.name.compareTo(s2.name);
		
	
	}
	
}
public class Lab13 {

	
	public static void main(String[] args) {
		
	ArrayList al=new ArrayList();	
	
	al.add(new Student1(1, "ajay", "lko"));
	al.add(new Student1(10, "aamit", "pnb"));
	al.add(new Student1(6, "ahjt", "up"));
	
	System.out.println("Sorting by age");
	
	Collections.sort(al,new AgeComparator());
	
	Iterator itr=al.iterator();
	
	while(itr.hasNext())
	{
		Student1 s3=(Student1)(itr.next());
		System.out.println(s3.age+" "+s3.name+" "+s3.address);
	}
	
	
System.out.println("Sorting by name");
	
	Collections.sort(al,new NameComparator());
	
	Iterator itr1=al.iterator();
	
	while(itr1.hasNext())
	{
		Student1 s3=(Student1)(itr1.next());
		System.out.println(s3.age+" "+s3.name+" "+s3.address);
	}
	

	}

}
